import * as types from '../mutation-types';
import Cookies from 'js-cookie';

//建议对于getters,actions都加上模块名
// initial state
const state = {
  theme: 2, //1.light 2.dark
  firstLoad: true //是否为第一次加载
}

// getters
const getters = {
  framework_theme: state => state.theme,
  framework_firstLoad: state => state.firstLoad
}

// actions
const actions = {
  //开启关闭左边菜单
  frameworkToggleLeftSideStatus ({ commit, state }) {
    commit(types.FRAMEWORK_TOGGLE_LEFTSIDEOPEN);
  }, 
  //切换框架是否为锁屏状态
  frameworkLock({ commit, state }) {
  	commit(types.FRAMEWORK_LOCK);
  },
  //切换框架为解锁状态
  frameworkUnLock({ commit, state }) {
  	commit(types.FRAMEWORK_UNLOCK);
  },
  //更新框架为非第一次更新
  frameworkUpdateFirstLoad({ commit, state }) {
  	commit(types.FRAMEWORK_UPDATE_FIRST_LOAD);
  }
}

// mutations
const mutations = {
  //开启关闭左边菜单
  [types.FRAMEWORK_TOGGLE_LEFTSIDEOPEN] (state) {
      state.leftSideOpen = !state.leftSideOpen;
  },
  //锁定屏幕
	[types.FRAMEWORK_LOCK](state) {
    Cookies.set('locking', '1');
	},
	//解锁屏幕
	[types.FRAMEWORK_UNLOCK](state) {
    Cookies.set('locking', '0');
	},
	//更新是否为第一次加载
	[types.FRAMEWORK_UPDATE_FIRST_LOAD](state) {
    state.firstLoad = false;
	}
}

export default {
  state,
  getters,
  actions,
  mutations
}